package servlet.request;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/9/28 10:11
 * @Description: 请求的字节编码
 */
@WebServlet(name = "charsetRequestServlet", value = {"/charsetRequest"})
public class CharsetRequestServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req,
      HttpServletResponse resp)
      throws ServletException, IOException {

    resp.setContentType("text/html");
    String name = req.getParameter("userName");
    resp.getWriter().println(name);
    System.out.println("name = "+name);
    String newname = new String(name.getBytes("ISO-8859-1"),"utf-8");
    System.out.println(newname);

  }

  @Override
  protected void doPost(HttpServletRequest req,
      HttpServletResponse resp)
      throws ServletException, IOException {
    doGet(req, resp);
  }
}
